// pages/index/components/job/job.js
import {
    anit
} from '../../../../utils/util'

import user from '../../../../utils/user.js'
import {
    getAccountExpireNotify
} from '../../../../api/app.js'
// const app = getApp()
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        item: Object
    },
    observers: {
        'item': function (data) {
            this.setData({
                data: data
            })
        }
    },
    data: {
        showMoreStatus: false,
        morePosition: 0,
        isAdmin: false,
        userId: '',
    },
    ready() {
        this.setData({
            isAdmin: (user.isAdmin || user.isSuperAdmin),
            userId: user.userId
        })
    },


    /**
     * 组件的方法列表
     */
    methods: {
        goProject(event) {
            if (anit(event)) {
                wx.navigateTo({
                    url: '/packagePay/pages/new-resident/new-resident?id=' + event.currentTarget.dataset.id,
                })
            }
        },
        hideMore() {
            this.setData({
                showMoreStatus: false
            })
        },
        // 显示更多
        async showMore(event) {
            console.log(event)
            const list = [{
                text: '项目归档',
                key: '',
                icon: '/assets/img/file.png',
                bind: 'placeFile'
            }, ]
            if (user.isAdmin) {
                list.push({
                    text: '修改名称',
                    key: '',
                    icon: '/assets/img/home/set.png',
                    bind: 'setName'
                })
            }
            this.setData({
                'moreList': list
            })
            // 如果距离底部太近，位置往上一点，不然会被tabbar遮住
            let systemInfo = await wx.getSystemInfo()
            let yPosition = event.touches[0].clientY + 20
            let addT
            if (systemInfo.windowHeight - event.touches[0].clientY < 200) {
                yPosition = event.touches[0].clientY - 120
            }
            this.setData({
                morePosition: yPosition,
                showMoreStatus: true
            })
        },
        onSetName() {
            this.triggerEvent('setName', this.data.data.id)
        },
        onPlaceFile() {
            this.triggerEvent('placeFile', this.data.data.id)
        },
        handleInvite() {
            wx.navigateTo({
                url: '/packagePay/pages/invitation-poster/invitation-poster?projectName=' + this.data.data.projectName + '&projectId=' + this.data.data.id
            })
        },
        // 跳转到支付页面
        async payWage() {
            if (this.data.data.peopleNum > 500) {
                app.alert('员工总数大于500，请使用PC端发薪')
                return
            }
            // if(!user.isOpenPaySalary){
            //     console.log('到这里啦')
            //     this.setData({
            //         isPopupPay:true
            //     })
            //     return
            // }
            const result = await getAccountExpireNotify()
            this.setData({
                expirationTime: result
            })
            if (result.status === 3) {
                this.setData({
                    ispopupRemind: true
                })
                return
            } else {
                this.expireCancel()
            }
            wx.navigateTo({
                url: '/packagePay/pages/pay-wage/pay-wage?id=' + this.data.data.id + '&type=' + this.data.data.type
            })
        },
        // 忽略发薪
        expireCancel() {
            this.setData({
                ispopupRemind: false
            })
        },
    }
})